﻿#include<opencv2/opencv.hpp>
using namespace cv;
int main()
{
	//Mat srcImag = imread("2.jpg"), grayImag, threImag, closeImag;
	//cvtColor(srcImag, grayImag, CV_BGR2GRAY);
	//GaussianBlur(grayImag, grayImag, Size(15, 15), 0);
	//threshold(grayImag, threImag, 150, 255, THRESH_BINARY);
	//morphologyEx(threImag, closeImag, MORPH_CLOSE, getStructuringElement(MORPH_RECT, Size(15, 15)));
	//morphologyEx(closeImag, closeImag, MORPH_OPEN, getStructuringElement(MORPH_RECT, Size(11, 11)));
	//dilate(closeImag, closeImag, getStructuringElement(MORPH_RECT, Size(15, 15)));
	//Canny(closeImag, closeImag, 10, 100);

	Mat srcImag,dilateImag,erodeImag, openImag, closeImag, topHatImag, blackHatImag, adT,threI, sobelImagx,sobelImagy,sobelImag, cannyImag;
	srcImag = imread("lena.png");
	Mat grayImag;
	cvtColor(srcImag, grayImag, CV_BGR2GRAY);

	//自适应阈值部分
	adT = grayImag.clone();
	adaptiveThreshold(adT, threI, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 7, 7);

	//形态学变换部分
	Mat structureElement = getStructuringElement(MORPH_RECT, Size(11, 11));
	dilate(grayImag, dilateImag, structureElement);
	erode(grayImag, erodeImag, structureElement);
	morphologyEx(grayImag, openImag, MORPH_OPEN, structureElement);
	morphologyEx(grayImag, closeImag, MORPH_CLOSE, structureElement);
	morphologyEx(grayImag, blackHatImag, MORPH_BLACKHAT, structureElement);
	morphologyEx(grayImag, topHatImag, MORPH_TOPHAT, structureElement);


	Sobel(grayImag, sobelImagx, grayImag.depth(), 1, 0, 5);
	Sobel(grayImag, sobelImagy, grayImag.depth(), 0, 1, 5);
	addWeighted(sobelImagx, 0.5, sobelImagy, 0.5, 0, sobelImag);


	Canny(grayImag, cannyImag, 100, 200);

}